#!/usr/bin/env python
# encoding: utf-8
"""
@Author: Beam
@Mail:506556658@qq.com
@file: authForm.py
@time: 2017/9/15 16:05
"""


from django import forms
from backend import models

class RegisterForm(forms.Form):
	username = forms.CharField(min_length=4,
	                           max_length=12,
	                           error_messages={'required':u'用户名不能为空','min_length':u"长度不能小于4位",'max_length':u"长度不能多于12位"},
	                           widget=forms.TextInput(attrs={'class':'form-username form-control','placeholder':'Username...'}),
	)
	password = forms.CharField(min_length=9,
	                           max_length=28,
	                           error_messages={'required':u"密码不能为空",'min_length':u"长度不能小于9位",'max_length':u"长度不能多于28位"},
	                           widget=forms.PasswordInput(attrs={'class':'form-password form-control','placeholder':'Password...'}),
	)
	email = forms.EmailField(required=False,
	                         error_messages={'required':u"邮箱不能为空",'invalid':u'邮箱格式错误',},
	                         widget=forms.EmailInput(attrs={'class':"form-control",'placeholder':u'邮箱'}),
	)

	dept = forms.ChoiceField(choices=[],
	                         widget=forms.widgets.Select,
	                         label='所在部门',
	)

	def __init__(self,*args,**kwargs):
		super(RegisterForm,self).__init__(*args,**kwargs)
		self.fields['dept'].choices = models.Department.objects.values_list('id', 'dept')  #这样每次实例化的时候都可以初始化这值